#第十七章 使用期物处理并发

#实例2 通过队并发加载20个国家的国旗图片

from concurrent import futures
from chp17_1flags import save_flag,get_flag,show,main

MAX_WORKERS = 20 #最大线程数

def  download_one(cc):
    img = get_flag(cc)
    show(cc)
    save_flag(img,cc.lower()+'.gif')    
    return cc

def download_many(cc_list):
    workers = max(MAX_WORKERS,len(cc_list))
    with futures.ThreadPoolExecutor(workers) as exctor:
        # 多线程执行download_one函数并且把cc_list的值传给download_one函数的参数,download_one每次返回的值都会存在res生成器中
        res = exctor.map(download_one,cc_list) 
        print('****************res=',res)
    res = list(res)
    print("------------------res===",res)
    return len(res)
    
if __name__ == "__main__":
    main(download_many)